package alg20241025;

public class Text2 {
    public int minOperations(int[] nums, int x) {
        int left = 0, right = 0, n = nums.length;
        int len = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += nums[i];
        }
        int target = sum - x;
        sum = 0;
        while(right < n){
           sum += nums[right];   //进窗口
           while(sum > target){
               sum -= nums[left++];   //出窗口
           }
           if(sum == target){
               len = Math.max(len, right - left + 1);    //更新结果
           }
        }
        return len;
    }

}
